Skip to content

Fix path_info pointer underflow in CGI fix_pathinfo handling - #23411

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/cgi-pathinfo-underflow
Open

Fix path_info pointer underflow in CGI fix_pathinfo handling#23411
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/cgi-pathinfo-underflow

Conversation

@iliaal

@iliaal iliaal commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

cgi.fix_pathinfo derived PATH_INFO as env_path_info + pilen - slen even when PATH_INFO was shorter than the suffix stripped from SCRIPT_FILENAME, which under-runs the pointer. FPM received this guard in ab061f9; CGI did not.

When the PATH_INFO supplied by the webserver is shorter than the
suffix stripped from SCRIPT_FILENAME, computing env_path_info +
pilen - slen underflows and the subsequent path_info[0] = 0 writes
out of bounds before the start of the string.

The FPM side of this same loop was hardened by commit ab061f9
(CVE-2019-11043) but sapi/cgi was never given the equivalent guard.
Mirror it: only derive path_info when pilen exceeds slen, and skip
the ORIG_*/SCRIPT_NAME juggling when there is no extracted path.
Comment on lines +29 to +30
@unlink($f);
@rmdir($d);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@unlink($f);
@rmdir($d);
?>
--CLEAN--
<?php
$d = __DIR__ . '/fix_pathinfo_underflow';
@unlink($d . '/info.php');
@rmdir($d);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants